home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr37
/
satsfaxt.zip
/
CCPUTILS.ZIP
/
CCSAVEF.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-01-30
|
12KB
|
267 lines
/*----------------------------------------------------------------------------*
* CCSAVEF.C *
*----------------------------------------------------------------------------*
* The program allows the user to move or fax received from an Intel *
* Connection CoProcessor or Group III fax machine to a normal MS-DOS *
* file. The file can be moved to any pre-existing path on any disk drive. *
* *
* The following source code is intended to assist developers in *
* creating applications which support the DCA/Intel Communicating *
* Applications Specification Version 1.0A. It is provided free of charge *
* and on an as-is basis. THE IMPLIED WARRENTIES OF MERCHANTABILITY AND *
* FITNESS FOR A PARTICULAR PURPOSE ARE SPECIFICALLY EXCLUDED. This source *
* code may be modified, enhanced, copied and distributed with applications *
* that support CAS on a royalty free basis. *
*----------------------------------------------------------------------------*/
#include <stdio.h>
#include <dos.h>
#include <io.h>
#include <malloc.h>
#include <string.h>
#include "cas.h" /* Intel CAS header file. */
#include "parse.h" /* Command line parser header file. */
#include "util.h" /* CAS utilities header file. */
int JobNo = 0; /* Job number to move. */
int Help = FALSE; /* Show help text. */
int RedirOut = FALSE; /* Redirect output to file. */
int Delete = FALSE; /* Delete after moving. */
ECF *TCFbuffer; /* Task Control File buffer. */
FTR *FTRbuffer; /* File Transfer Record buffer. */
FILE *ccout; /* Redirected stdout file. */
STABLE SwitchTable [] = /* Command line parser switch table. */
{
{ 'D', BOOL, &Delete },
{ 'd', BOOL, &Delete },
{ 'E', INT, &JobNo },
{ 'e', INT, &JobNo },
{ 'R', BOOL, &RedirOut },
{ 'r', BOOL, &RedirOut },
{ '?', BOOL, &Help }
};
#define TABLESIZE (sizeof(SwitchTable)/sizeof(STABLE))
char *DescTable[] = /* Help function description table. */
{
"CCSAVEF (V1.0) Save a fax received from a Group III fax machine as the file\n",
"specified by \"filename\". \"filename\" may include a path (for example,\n",
"c:\wp\sales.fax.\n\n",
"/E<number. save the event specified by <number> (for example, /e16041). CCAM\n",
"(Connection CoProcessor Application Manager) assigns numbers to the events\n",
"it processes. You can see the numbers of all send and receive events by typing\n",
"CCSTAT with no options.\n\n",
"Syntax: CCSAVEF /E<number> filename [option]\n\n"
};
#define DESCSIZE (sizeof(DescTable)/sizeof(DescTable[0]))
char *HelpTable[] = /* Help function switch table. */
{
" /D Delete event after moving files.\n\n",
" /R Redirect output to file OUTPUT.CC.\n",
" /? Display help information.\n"
};
#define HELPSIZE (sizeof(HelpTable)/sizeof(HelpTable[0]))
/*---------------------------------------------------------------------------*
* GetTaskBuffer() *
*---------------------------------------------------------------------------*
* Get information about the event specified by Handle. The Task Control *
* File is opened and read. The FileHandle returned is a normal MS-DOS file *
* handle. *
*---------------------------------------------------------------------------*
* Parameters: int Handle - Event handle to return information from. *
* BYTE Queue - Queue (Task, Log or Receive) to get event from. *
* char *TCFbuffer - Uninitialized ECS structure, filled with *
* task info on return. *
* int *FileHandle - Filled with DOS file handle on return. *
* Return: none *
*---------------------------------------------------------------------------*/
GetTaskBuffer(int Handle, BYTE Queue, char *TCFbuffer, int *FileHandle)
{
/* Let CAS open the Task Control File. Read the contents into TCFbuffer. */
if((*FileHandle = CASOpenFile(Handle,0,Queue)) > 0) {
read(*FileHandle, TCFbuffer, sizeof(ECF));
}
else
CASError(CASNOTCF, TRUE, -(*FileHandle));
}
/*---------------------------------------------------------------------------*
* GetFileTransferBuffer() *
*---------------------------------------------------------------------------*
* Get information about the File Transfer Record. Offset specifies the *
* location within the Task Control File of the FTR record. Usually, the *
* first FTR is at offset 383 in the TCF (if no cover text). In any case, *
* the offset of the first FTR is stored at offset 10 of the TCF. Each *
* subsequent FTR is 128 bytes after the first. *
*---------------------------------------------------------------------------*
* Parameters: long Offset - File offset to begin reading. *
* char *FTRbuffer - Uninitialized FTR structure, filled with *
* file transfer info on return. *
* int *FileHandle - DOS file handle obtained from a call to *
* CASOpenFile(). *
* Return: none *
*---------------------------------------------------------------------------*/
GetFileTransferBuffer(long Offset, char *FTRbuffer, int *FileHandle)
{
/* Read the File Transfer Record specified by Offset. */
lseek(*FileHandle, Offset, SEEK_SET);
read(*FileHandle, FTRbuffer, sizeof(FTR));
}
/*---------------------------------------------------------------------------*
* OkayToMove() *
*---------------------------------------------------------------------------*
* OkayToMove checks for existence of FileName. If the file does not exist, *
* the function returns TRUE. If it exists, CAS Move Received File will *
* fail, so the user is prompted for permission to overwrite. If permission *
* is granted, the file is removed and the function returns true. If the *
* removal fails or the user does not give permission, the function returns *
* false. *
*---------------------------------------------------------------------------*
* Parameters: char *FileName - Path and name of file to test. *
* Return: TRUE if it is okay to call CASMoveReceivedFile, FALSE *
* otherwise. *
*---------------------------------------------------------------------------*/
int OkToMove (char *FileName)
{
char answer[1]; /* Users response to confirmation quest. */
/* Check to see if file already exists. */
if(!access(FileName,0)) {
/* Confirm overwrite on existing file. */
fprintf(stderr," File %s already exists - overwrite? (y/n)", strupr(FileName));
gets(answer);
if(toupper(answer[0]) == 'Y') {
/* If we can't remove the existing file, don't try saving fax. */
if(remove(FileName) == -1) {
CASError(CASDELJOB, FALSE, 0);
return(FALSE);
}
/* OK, save the fax as planned. */
return(TRUE);
}
/* No permission to overwrite. */
else
return(FALSE);
}
/* File doesn't already exist - go ahead and save fax. */
else
return(TRUE);
}
/*---------------------------------------------------------------------------*
* MoveFile() *
*---------------------------------------------------------------------------*
* Move all faxes associated with the event specified by EventHandle. The *
* faxes are moved to the path NewFilePath given on the command line. Each *
* fax is named as the last componant of the specified path name. Therefore, *
* the command line must include a fully qualified file name. *
*---------------------------------------------------------------------------*
* Parameters: int EventHandle - Event handle containing the file to move. *
* char *NewFilePath - The drive and path where file is to be *
* move. The last componant is the file name. *
* ECF *TCFbuffer - Uninitialized ECF structure, filled with *
* Task Control info in return. *
* FTR *FTRbuffer - Uninitialized FTR structure, filled with *
* file transfer info on return. *
* Return: none *
*---------------------------------------------------------------------------*/
MoveFile(int EventHandle, char *NewFilePath, ECF *TCFbuffer, FTR *FTRbuffer)
{
int ErrorCode; /* Error return from CAS function. */
long Offset; /* Offset of FTR in task control file. */
int FileHandle; /* DOS file handle (from GetTaskBuffer). */
/* Get information about the task. */
GetTaskBuffer(EventHandle, RECEIVE_QUEUE, (char *)TCFbuffer, &FileHandle);
/* The FTR is at the offset stored at FTROffset in the TCF.
This will vary depending on if cover text was sent. */
Offset = TCFbuffer->FTROffset;
/* Get information about the fax that was transferred. */
GetFileTransferBuffer(Offset, (char *)FTRbuffer, &FileHandle);
/* Error - this routine only for FAXes. */
if(TCFbuffer->TransferType == FILE_TRANSFER)
CASError(CASNOTFAX, TRUE, 0);
/* Move the received fax to the new path and file name. */
if(OkToMove(NewFilePath))
if((ErrorCode = CASMoveReceivedFile(EventHandle, 1, NewFilePath)) != SUCCESS) {
CASError(CASMOVE, FALSE, -ErrorCode);
/* Make sure we don't delete the event! */
Delete = FALSE;
}
close(FileHandle);
if(Delete)
CASDeleteFile(EventHandle, 0, LOG_QUEUE);
}
/*---------------------------------------------------------------------------*
* Main *
*---------------------------------------------------------------------------*
* Move all faxes from a receive event to the specified directory. *
* The user specifies the directory and filename on the command line. *
*---------------------------------------------------------------------------*
* Return: The DOS exit code is 0 if no errors are encountered, 1 for *
* commandline syntax errors, 2 for CCAM error, and 3 for DOS *
* errors. *
*---------------------------------------------------------------------------*/
main(int argc, char **argv)
{
int result; /* DOS & CAS function return value. */
argc = ParseCommand(argc, argv, SwitchTable, TABLESIZE);
/* If help is wanted, print info and exit (with 0 exit code). */
if(Help || (argc == 1))
CASHelp(DescTable, DESCSIZE, HelpTable, HELPSIZE);
/* Insure that the Resident Scheduler is installed. */
if((result = CASGetInstalledState()) != INSTALLED) {
if( result == NOTiOK )
CASError(CASNOHWO, TRUE, 0);
else
CASError(CASNOHWN, TRUE, 0);
}
/* Redirect stdout to a file. */
if(RedirOut) {
if((ccout = fopen("OUTPUT.CC", "w")) == NULL)
CASError(CASOPENTEMP, TRUE, 0);
if(-1 == dup2(fileno(ccout), 1))
CASError(CASBADREDIR, TRUE, 0);
}
/* Check to make sure that a (one only) path name was specified. */
if(argc < 2)
CASError(CASARGPATH, TRUE, 0);
else if(argc > 2)
CASError(CASARGMULTPATH, TRUE, 0);
/* Get buffer for Task information. */
TCFbuffer = (ECF *)malloc(sizeof(ECF));
if(TCFbuffer == NULL)
CASError(CASNOMEM, TRUE, 0);
/* Get buffer for File Transfer information. */
FTRbuffer = (FTR *)malloc(sizeof(FTR));
if(FTRbuffer == NULL)
CASError(CASNOMEM, TRUE, 0);
/* Point to path name and move it! */
argv++;
MoveFile(JobNo, *argv, TCFbuffer, FTRbuffer);
exit(0);
}